layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    var request = GetRequest();
    $.get("/checkitem/" + request.id,function (data) {
        $("#id").val(request.id);
        $("#chtypeNo").val(data.chtypeNo);
        $("#name").val(data.name);
        $("#devModel").val(data.devModel);
        $("#code").val(data.code);
        $("#chDecDig").val(data.chDecDig);
        $("#unit").val(data.unit);
        $("#corrUnit").val(data.corrUnit);
        $("#chMax").val(data.chMax);
        $("#chMin").val(data.chMin);
        $("#chCorrCyc").val(data.chCorrCyc);
        $("#chCorrFormula").val(data.chCorrFormula);
        $("#remarks").val(data.remarks);
    });

    //修改场景信息
    form.on('submit(edit)', function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            url: '/checkitem/edit',
            data:data.field,
            type:'POST',
            success: function (data) {
                if(data.code == 200) {
                    top.layer.close(index);
                    top.layer.msg("修改成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                } else {
                    top.layer.close(index);
                    top.layer.msg("修改失败！");
                }
            },
            error:function () {
                top.layer.close(index);
                top.layer.msg("修改失败！");
            }
        });
        return false;
    });

    //获取路径中的参数
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }


});